package com.xja.shoppingmall.config;

import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @author CHENCHEN
 * @title   Swagger配置类
 *      原生：/swagger-ui.html
 *      美化：/doc.html
 * @createTime 2021-12-1321:12
 */
@Configuration
@EnableSwagger2
public class SwaggerConfig {

    /**
     * Swagger实例Bean是Docket，通过Docket来配置Swagger
     * @return
     */
    public Docket docket(){
        return new Docket(DocumentationType.SWAGGER_2)
                //展示在swagger页面上的自定义工程描述
                .apiInfo(apiInfo())
                //选择展示那些接口
                .select()
                //只有在com.xja.shoppingmall 包下的才去展示
                .apis(RequestHandlerSelectors.basePackage("com.xja.shoppingmall"))
                .paths(PathSelectors.any())
                .build();

    }

    /**
     * Swagger描述信息
     * @return
     */
    public ApiInfo apiInfo(){
        return new ApiInfoBuilder()
                .title("shopping-mall-servers API doc")
                .description("这里是描述")
                .contact(new Contact("这里是名字","这里是链接地址", "这里是邮箱"))
                .version("当前版本 1.0")
                .build();
    }
}
